#include <QDebug>

#include "roaditem.h"

RoadItem::RoadItem(vector<Lane> &vecLane, QPolygonF &qpolygonPoint)
{
}

RoadItem::~RoadItem()
{
}

QPainterPath RoadItem::shape() const
{
    QPainterPath path;
    path.addPolygon(m_qpolygonPoint);
    path.lineTo(m_qpolygonPoint[0]);
    return  path;
}

void RoadItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
{
//    QPainterPath path;
//    painter->drawPolygon(m_qpolygonPoint);
//    path.addPolygon(m_qpolygonPoint);
    //this->setPath(path);
    painter->setRenderHint(QPainter::Antialiasing);
//    QPen pen(Qt::NoPen);
//    painter->setPen(pen);

//    for(int i = 0; i < m_qlstLaneItem.size(); i++)
//    {
//        painter->setBrush(__RODADATA->getColor(m_qlstLaneItem[i]->getLaneType()));
//        painter->drawPath(m_qlstLaneItem[i]->shape());
//    }

//    for(int i = 0; i < m_qlstLaneLine.size(); i++)
//    {
//        pen.setColor(__RODADATA->getColor(m_vecLane[i].roadMark.color.c_str()));
//        pen.setStyle(__RODADATA->getPenStyle(m_vecLane[i].roadMark.type.c_str()));
//        pen.setWidthF(0.1);
//        painter->setPen(pen);
//        painter->drawPolyline(m_qlstLaneLine[i]);
//    }

    if(m_bShowRoad)
    {
        painter->setBrush(QColor(255, 255, 0, 100));
        painter->setPen(QPen(Qt::red, 0.1));
        painter->drawPolygon(m_qpolygonPoint);
    }
    else
    {
        painter->setBrush(Qt::NoBrush);
        painter->setPen(Qt::NoPen);
    }
}

void RoadItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
}

void RoadItem::setLaneOffsets(const QVector<SLaneOffset> &qvecLaneOffset)
{
    m_qvecLaneOffset = qvecLaneOffset;
}

void RoadItem::setElevations(const QVector<SElevation> &qvecElevation)
{
    m_qvecElevation = qvecElevation;
}

QVector<SLaneOffset> RoadItem::getLaneOffsets() const
{
    return m_qvecLaneOffset;
}

void RoadItem::appendLaneOffset(const SLaneOffset &laneOffset)
{
    m_qvecLaneOffset.append(laneOffset);
}

QVector<SElevation> RoadItem::getElevations() const
{
    return m_qvecElevation;
}

void RoadItem::appendElevation(const SElevation &elevation)
{
    m_qvecElevation.append(elevation);
}

void RoadItem::setPolygonPoint(const QPolygonF &qpolygonPoint)
{
    m_qpolygonPoint = qpolygonPoint;
}

void RoadItem::setObject(const QVector<Object> &qvecObject)
{
    m_qvecObject = qvecObject;
}

void RoadItem::setLaneLine(const QList<QPolygonF> &qlstLaneLine)
{
    m_qlstLaneLine = qlstLaneLine;
}

void RoadItem::appendLaneLine(const QPolygonF &polygon)
{
    m_qlstLaneLine.append(polygon);
}

void RoadItem::appendLaneItem(LaneItem *pLaneItem)
{
    m_qlstLaneItem.append(pLaneItem);
}

void RoadItem::appendLane(const SLane &lane)
{
    m_vecLane.push_back(lane);
}

QString RoadItem::getType() const
{
    return m_qstrType;
}

void RoadItem::setType(const QString &qstrType)
{
    m_qstrType = qstrType;
}

QString RoadItem::getId() const
{
    return m_qstrId;
}

void RoadItem::setId(const QString &qstrId)
{
    m_qstrId = qstrId;
}

void RoadItem::onRoad(LaneItem *pLaneItem, const QPointF &pointf)
{
    sigRoad(this, pLaneItem, pointf);
}

void RoadItem::onClick()
{
    m_bShowRoad = !m_bShowRoad;
    update();
}
